package com.txz.web.controller.common;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.txz.common.config.TxzConfig;
import com.txz.common.core.domain.AjaxResult;
import java.io.File;

/**
 * 图片调试控制器
 */
@RestController
@RequestMapping("/debug/images")
public class ImageDebugController {

    /**
     * 调试图片路径
     */
    @GetMapping("/paths")
    public AjaxResult debugPaths() {
        String uploadPath = TxzConfig.getUploadPath();
        File imagesDir = new File(uploadPath + "/images");

        // 检查目录是否存在
        boolean exists = imagesDir.exists();
        boolean isDirectory = imagesDir.isDirectory();

        // 如果目录不存在，尝试创建
        if (!exists) {
            boolean created = imagesDir.mkdirs();
            return AjaxResult.success("目录不存在，已尝试创建: " + created);
        }

        // 列出目录内容
        File[] files = imagesDir.listFiles();
        int fileCount = files != null ? files.length : 0;

        return AjaxResult.success("上传路径: " + uploadPath + 
                               ", 目录存在: " + exists + 
                               ", 是目录: " + isDirectory + 
                               ", 文件数量: " + fileCount);
    }
}
